package com.macro.mall.portal.service.impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.SmsMessageHistoryMapper;
import com.macro.mall.model.SmsMessageHistory;
import com.macro.mall.model.SmsMessageHistoryExample;
import com.macro.mall.portal.domain.SmsMessageHistoryQueryParam;
import com.macro.mall.portal.service.SmsMessageHistoryService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * &#064;author：郎 \n
 * &#064;name：SmsMessageHistoryServiceImpl /n
 * &#064;date：2023/12/11  17:14
 */
@Service
@AllArgsConstructor
public class SmsMessageHistoryServiceImpl implements SmsMessageHistoryService {
    private final SmsMessageHistoryMapper smsMessageHistoryMapper;

    /**
     * 创建商品
     *
     * @param entity
     */
    @Override
    public Boolean save(SmsMessageHistory entity) {
        return smsMessageHistoryMapper.insertSelective(entity) > 0;
    }

    /**
     * 根据短信编号获取更新信息
     *
     * @param id
     */
    @Override
    public SmsMessageHistory getMessageHistoryInfo(Long id) {
        return smsMessageHistoryMapper.selectByPrimaryKey(id);
    }

    /**
     * 分页查询商品
     *
     * @param queryParam
     * @param pageSize
     * @param pageNum
     */
    @Override
    public List<SmsMessageHistory> list(SmsMessageHistoryQueryParam queryParam, Integer pageSize, Integer pageNum) {
        SmsMessageHistoryExample example = new SmsMessageHistoryExample();
        SmsMessageHistoryExample.Criteria criteria = example.createCriteria();
        if (StrUtil.isBlank(queryParam.getPhone())) {
            criteria.andPhoneLike(queryParam.getPhone());
        }
        if (StrUtil.isBlank(queryParam.getTemplateId())) {
            criteria.andTemplateIdEqualTo(queryParam.getTemplateId());
        }
        if (StrUtil.isBlank(queryParam.getSourceType())) {
            criteria.andSourceTypeEqualTo(queryParam.getSourceType());
        }
        PageHelper.startPage(pageNum, pageSize);
        return smsMessageHistoryMapper.selectByExample(example);
    }
}
